package com.zhou.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zhou.constant.MessageConstant;
import com.zhou.entity.PageResult;
import com.zhou.entity.QueryPageBean;
import com.zhou.entity.Result;
import com.zhou.pojo.CheckItem;
import com.zhou.pojo.Member;
import com.zhou.service.MemberService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/member")
public class MemberController {
    @Reference
    MemberService memberService;
    @RequestMapping("/add")
    public Result add(@RequestBody Member member){
        try {
            memberService.add(member);
            return new Result(true, MessageConstant.ADD_MEMBER_SUCCESS);
        }catch (Exception e){
            return new Result(false,MessageConstant.ADD_MEMBER_FAIL);
        }
    }
    //分页查
    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult findpage=memberService.findPage(
                queryPageBean.getCurrentPage(),
                queryPageBean.getPageSize(),
                queryPageBean.getQueryString());
        return findpage;
    }
    @GetMapping("/delete")
    public Result delete(Integer id){
        try {
            memberService.delete(id);
            return new Result(true,MessageConstant.DELETE_MEMBER_SUCCESS);
        }catch (Exception e){
            return new Result(false,MessageConstant.DELETE_MEMBER_FAIL);
        }
    }
    @RequestMapping("/edit")
    public Result edit(@RequestBody Member member){
        try {
            memberService.edit(member);
            return new Result(true,MessageConstant.EDIT_MEMBER_SUCCESS);
        }catch (Exception e){
            return new Result(false,MessageConstant.EDIT_MEMBER_FAIL);
        }
    }
    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            Member byId = memberService.findById(id);
            return new Result(true,MessageConstant.QUERY_MEMBER_SUCCESS,byId);
        }catch (Exception e){
            return new Result(false,MessageConstant.QUERY_MEMBER_FAIL);
        }
    }
    @GetMapping("/findAll")
    public Result findAll(){
        try {
            List<Member> all = memberService.findAll();
            return new Result(true,MessageConstant.QUERY_MEMBER_SUCCESS,all);
        }catch (Exception e){
            return new Result(false,MessageConstant.QUERY_MEMBER_FAIL);
        }
    }
    //手机号验证
    @RequestMapping("/phoneValidator")
    public String phoneValidator(@RequestBody Member member) {
        return memberService.phoneValidator(member);
    }
    //身份证验证
    @RequestMapping("/idCardValidator")
    public String idCardValidator(@RequestBody Member member) {
        return memberService.idCardValidator(member);

    }
    @RequestMapping("/fileNumberValidator")
    public String fileNumberValidator(@RequestBody Member member) {
        return memberService.fileNumberValidator(member);
    }
}
